package com.bandapp.ui;

import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;

import android.app.ListActivity;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;

import com.bandapp.adapters.TwitterFeedAdapter;
import com.bandapp.bo.Band;
import com.bandapp.rss.TwitterRSSItem;
import com.bandapp.rss.TwitterRSSWrapper;

/*
 * Here we represent a RSSFeed from the twitter account of Amatorski
 * Later on we will have to make some sort of twidroid app. so that users can reply from their android phones to the twitter of the band
 */
public class RSSFeedActivity extends ListActivity {	
		
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.rss_feed_activity);
		Bundle extras = getIntent().getExtras();
		Integer position = extras.getInt("position");
		
		/*
		 * twitter feed in rss
		 */
		URL twitterFeedURL;
		try {
			/*
			 * get the band that was clicked, and it's feed 
			 * TODO default text for a band that has no feed
			 */
			
			Band band = Main.bands.get(position);
			
			/*
			 * get feeds
			 */
			twitterFeedURL = band.getBandFeed();
			TwitterRSSWrapper twitterRSSWrapper = new TwitterRSSWrapper(twitterFeedURL);
			
			ArrayList<TwitterRSSItem> listOfItems = twitterRSSWrapper.getItems();
			
			/*
			 * get image to show in each row
			 */
			AssetManager assetManager = getAssets();
			InputStream stream = assetManager.open(band.getImageForFeed());
			Bitmap bmp = BitmapFactory.decodeStream(stream);
			TwitterFeedAdapter tfAdapter = new TwitterFeedAdapter(this,R.layout.custom_row_feed,listOfItems,bmp);
			
			setListAdapter(tfAdapter);
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
				
	}
	
}
